package com.qf.entity;

public class Page {
    //页码, 当前页数
    private Integer pageIndex;
    //页大小  显示多少行数据
    private Integer pageSize;
    //数据的总行数
    private Integer totalCounts;
    //总页数, 一共有多少页
    //总页数 = 总条数 % 每页显示条数 == 0 ? 总条数 /每页显示条数 : 总条数 /每页显示条数 +1
    private Integer totalPages;
    //起始行, 从第几条开始查询 = (当前页数 - 1) * 每页显示数据条数
    private Integer startRows;

    public Page(Integer pageIndex) {
        this.pageIndex = pageIndex;
        //初始化每页显示条数, 默认每页显示5条数据
        this.pageSize = 5;
    }

    public Page(Integer pageIndex, Integer pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        //初始化每页显示条数, 默认每页显示5条数据
        this.pageSize = 5;
        this.setStartRows((pageIndex - 1) * pageSize);
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(Integer totalCounts) {
        this.totalCounts = totalCounts;
        //在设置总条数的时候, 顺便计算总页数
        this.setTotalPages(totalCounts % pageSize == 0 ? totalCounts / pageSize : totalCounts / pageSize + 1);
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRows(Integer startRows) {
        this.startRows = startRows;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", totalCounts=" + totalCounts +
                ", totalPages=" + totalPages +
                ", startRows=" + startRows +
                '}';
    }
}
